home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gold Medal Software 3
/
Gold Medal Software - Volume 3 (Gold Medal) (1994).iso
/
prog
/
proxy14.arj
/
H7.HLP
< prev
next >
Wrap
Text File
|
1992-12-05
|
1KB
|
37 lines
STRUCTS
struct sname { f1,...,fn; }; struct declaration
new sname(e1, ..., en) struct instantiation
s . fi ; struct component selection
s . fi = e ; struct component update
Structs are data structures whose components may be selected by name.
The typical operations are declaration, instantiation, selection and
update.
A struct declaration is essentially a class declaration which defines
the names of the components of the struct. The syntax of the declaration
is best shown by an example.
struct item {partno, code, quantity;};
The above declaration defines item to be a struct with the (field)
names partno, code and quantity. Various items can be instantiated
(created) by providing the struct name and values for the fields.
(but a struct component may not be a function).
i1=new item(124,"receipt",15);
i2=new item(126,"issue",7);
Components of structs may be selected using a dot notation similar
to records in Pascal and structures in C.
i1.code; returns "receipt"
i2.quantity; returns 7
Component values may be updated using assignment and dot notation.
i1.quantity=22; assigns 22 as the new value of the quantity
field.